/*
 * Copyright 2009 Yannick Stucki (yannickstucki.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.yannickstucki.android.musicqueue.old;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.net.Uri;

import com.yannickstucki.android.musicqueue.R;
import com.yannickstucki.android.musicqueue.util.Logger;

/**
 * A class that creates all the dialogs and forwards the interaction to a
 * {@link DialogHandler}.
 * 
 * @author Yannick Stucki (yannickstucki@gmail.com)
 * 
 */
public class DialogManager {

  /**
   * Displays the help dialog which features an explanatory text and a button to
   * the home page.
   */
  public static final int DIALOG_HELP = 0;

  /**
   * Displays the settings which currently only allow to toggle the use of the
   * head set button.
   */
  public static final int DIALOG_SETTINGS = 1;

  /**
   * Creates and returns a {@link Dialog} object.
   */
  public Dialog createDialog(final Context context, final DialogHandler dialogHandler, int id,
      boolean enableHeadsetButtonIn) {

    final Resources resources = context.getResources();
    switch (id) {
    case DIALOG_HELP:

      return new AlertDialog.Builder(context).setIcon(R.drawable.ic_menu_help).setTitle(
          R.string.help).setMessage(R.string.help_text).setPositiveButton(R.string.ok,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              // User clicked OK, do nothing
            }
          }).setNeutralButton(R.string.visit_website, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
          dialogHandler.openWebsite(Uri.parse(resources.getString(R.string.website)));
        }
      }).create();
    default:
      Logger.error("ERROR: This dialog id does not exist: " + id);
      break;
    }
    return null;
  }
}
